/*=================================全局变量定义============================================================*/

/*=================================页面事件============================================================*/
function homeLoad(){
	queryKYXXTitle();//获取指定数量客运信息的标题和时间
	queryHYDTTitle();//获取指定数量行业动态的标题和时间
	queryAllSettings();//获取所有settings的纪录
}

//在首页，点击客运信息的新闻，打开对应的新闻内容
function loadOneKYXX(newsID){
	var obj = window;
    obj.newsID = newsID;
	window.open("/PLDCarWeb/xwjj/kyxxContent.jsp?id="+ Math.random());
}
//在首页，点击行业动态的新闻，打开对应的新闻内容
function loadOneHYDT(newsID){
	var obj = window;
    obj.newsID = newsID;
	window.open("/PLDCarWeb/xwjj/hydtContent.jsp?id="+ Math.random());
}

/*=================================信息获取============================================================*/
//获取指定数量客运信息的标题和时间
function queryKYXXTitle(){
	if(bXmlHttpSupport) {
    	var sUrl = 'queryKYXXTitle.action';
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
        		//alert(request.responseText);
            	var oRequest = eval('(' + request.responseText + ')');
            	var KYXXTitleList = oRequest.KYXXList;
            	putKYXXTitleToLeftTopWindow(KYXXTitleList);
            	putKYXXIntoTable(KYXXTitleList);
            	makeTableColor("tableHomeKYXX","#FFCC66","white");//给页面的table的行改变颜色
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(null);
    }
}

//获取指定数量行业动态的标题和时间
function queryHYDTTitle(){
	if(bXmlHttpSupport) {
    	var sUrl = 'queryHYDTTitle.action';
        var request = new XMLHttpRequest();
        request.onreadystatechange = function() {
        	if(request.readyState == 4) {
            	var oRequest = eval('(' + request.responseText + ')');
            	var HYDTTitleList = oRequest.HYDTList;
            	putHYDTIntoTable(HYDTTitleList);
            	makeTableColor("tableHomeHYDT","#FFCC66","white");//给页面的table的行改变颜色
            	
			}
    	};
    	request.open('POST', sUrl);
    	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
    	request.send(null);
    }
}

/*=================================数据处理============================================================*/
//将客运信息放到左上的滚动窗口中
function putKYXXTitleToLeftTopWindow(KYXXTitleList){
	var string = "";
	for (var i in KYXXTitleList){
		string = string + "<li><a href='javascript:loadOneKYXX("+KYXXTitleList[i][0]+");'>"+createTitileString(KYXXTitleList[i][1],16)+"</a></li>";
	}
	leftNewsList.innerHTML = string;
}

//将客运信息列表放入table中
function putKYXXIntoTable(KYXXTitleList){
	var rowlength = tableHomeKYXX.rows.length; 
	for(var i=0;i <rowlength;i++) { 
		tableHomeKYXX.deleteRow(0); 
	}
	for (var i in KYXXTitleList){
		var rowObj = document.createElement("tr");
		addOneTD(rowObj, "▶&nbsp" + "<a href='javascript:loadOneKYXX("+KYXXTitleList[i][0]+");'>" + createTitileString(KYXXTitleList[i][1],30) + "</a>", "tdFirst");
		addOneTD(rowObj, KYXXTitleList[i][2].replace("T", " "), "tdLast");
		tableHomeKYXX.appendChild(rowObj);
	}
}

//将行业动态列表放入table中
function putHYDTIntoTable(HYDTTitleList){
	var rowlength = tableHomeHYDT.rows.length; 
	for(var i=0;i <rowlength;i++) { 
		tableHomeHYDT.deleteRow(0); 
	}
	for (var i in HYDTTitleList){
		var rowObj = document.createElement("tr");
		addOneTD(rowObj, "▶&nbsp" + "<a href='javascript:loadOneHYDT("+HYDTTitleList[i][0]+");'>" + createTitileString(HYDTTitleList[i][1],30) + "</a>", "tdFirst");
		addOneTD(rowObj, HYDTTitleList[i][2].replace("T", " "), "tdLast");
		tableHomeHYDT.appendChild(rowObj);
	}
}

/*=================================其他============================================================*/
//给页面的table的行改变颜色
function makeTableColor(obTable, hoverColor, outColor) {
	var t = document.getElementById(obTable).getElementsByTagName("tr");
	for ( var i = 0; i < t.length; i++) {
		t[i].onmouseover = function() {
				this.style.backgroundColor = hoverColor;
		};
		t[i].onmouseout = function() {
				this.style.backgroundColor = outColor;
		};
	}
}
